﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace ExcelXmlExpPic
{
    internal class PathFun
    {
        public static string[] PickFile(OpenFileDialog fileDialog, string myType = "ex", bool isMulti = false, string fd0 = "", string elseStrF = "")
        {
            string[]? fileNames = null;
            string strFilt = "";

            // 默认路径
            if (!string.IsNullOrEmpty(fd0))
            {
                fileDialog.InitialDirectory = fd0;
            }

            // 文件筛选
            switch (myType.ToUpper())
            {
                case "EX":
                    strFilt += "Excel (*.xls;*.xlsx)|*.xls;*.xlsx|";
                    break;
                case "TXT":
                    strFilt += "Txt files (*.txt;*.csv)|*.txt;*.csv|";
                    break;
                default:
                    if (!string.IsNullOrEmpty(elseStrF))
                    {
                        strFilt += elseStrF + "|";
                    }
                    break;
            }

            strFilt += "All Files (*.*)|*.*";
            fileDialog.Filter = strFilt;

            // 多选
            fileDialog.Multiselect = isMulti;
            fileDialog.SupportMultiDottedExtensions = true;

            if (fileDialog.ShowDialog() == DialogResult.OK)
            {
                fileNames = fileDialog.FileNames ;
            }

            return fileNames ?? Array.Empty<string>();
        }
    }
}
